Skip to content

Raise ArgumentTypeError for non-string variant choices - #131

Merged
njzjz merged 2 commits into
deepmodeling:masterfrom
sapunyangkut:codex/issue-119-nonstring-choice-errors
Aug 30, 2026
Merged

njzjz merged 2 commits into
deepmodeling:masterfrom
sapunyangkut:codex/issue-119-nonstring-choice-errors

Conversation

@sapunyangkut

@sapunyangkut sapunyangkut commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • validate a variant tag's type before alias dictionary membership or spelling suggestions
  • raise the structured ArgumentTypeError for list, mapping, numeric, and null tags instead of leaking raw TypeError
  • preserve alias normalization and Did you mean behavior for string values

Fixes #119.

Validation

  • focused regression: 1 passed on the exact upstream base and patch
  • adjacent checker tests: 13 passed on the exact upstream base and patch
  • full suite: 50 passed on the exact upstream base and patch
  • git diff --check, Python AST checks, and a bounded manual security review passed in the publication worktree
  • the current publication environment could not recollect pytest because typeguard is not installed; no dependencies were installed for this submission

AI assistance disclosure

This change was prepared and tested with OpenAI Codex. It is intentionally opened as a Draft for maintainer review. No automated issue/PR comments or Ready transition will be made.

Summary by CodeRabbit

  • Bug Fixes

    • Improved validation for variant choices, including clearer errors when values use an unsupported type.
    • Enhanced suggestions for misspelled choice tags.
    • Ensured aliases consistently resolve to their corresponding canonical choices.
  • Tests

    • Added coverage for invalid types, aliases, and misspelled choice suggestions.

sapunyangkut and others added 2 commits July 16, 2026 20:31
Validate variant tags before alias lookup or spelling suggestions so invalid list, mapping, numeric, and null values raise ArgumentTypeError instead of raw TypeError.

AI-assisted by OpenAI Codex; submitted as a Draft for maintainer review.
@coderabbitai

coderabbitai Bot commented Jul 16, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Variant choice handling now rejects non-string discriminator values with structured type errors, includes aliases in expected-choice suggestions, preserves alias normalization, and adds tests for invalid types, aliases, and misspelled tags.

Changes

Variant choice validation

Layer / File(s) Summary
Choice type and alias handling
dargs/dargs.py, tests/test_checker.py
Variant validates string discriminator values, combines direct tags and aliases for suggestions, restricts alias conversion to strings, and tests the resulting errors and normalization.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The changes address #119 by rejecting non-string variant tags with structured ArgumentTypeError and preserving value suggestions.
Out of Scope Changes check ✅ Passed The edits stay focused on variant choice validation and its tests, with no明显 unrelated scope added.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: raising ArgumentTypeError for non-string variant choices.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@codecov

codecov Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.23%. Comparing base (b4db564) to head (26b4aa9).
⚠️ Report is 11 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #131      +/-   ##
==========================================
+ Coverage   75.14%   75.23%   +0.08%     
==========================================
  Files           9        9              
  Lines         853      856       +3     
==========================================
+ Hits          641      644       +3     
  Misses        212      212              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@njzjz-bot njzjz-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the implementation, relevant tests, and CI results. No blocking correctness, security, or regression issue found.

Validation: pytest -q tests/test_checker.py (6 passed, 4 subtests); GitHub build, type-check, docs, pre-commit, and Codecov checks pass.

Coding agent: Codex
Codex version: codex-cli 0.151.0
Model: gpt-5.6-sol
Reasoning effort: xhigh

@njzjz-bot njzjz-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the non-string variant-choice validation and focused checker coverage. Invalid list, mapping, numeric, and null tags now raise structured ArgumentTypeError values, while string aliases and spelling suggestions remain intact; no blocking correctness, security, regression, or test issues found.\n\nCoding agent: Codex\nCodex version: codex-cli 0.151.0\nModel: gpt-5.6-sol\nReasoning effort: xhigh

@njzjz-bot njzjz-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed the variant-choice type validation and ran the complete checker test suite from the PR head; all six tests pass, including non-string tags, aliases, and invalid choices. The new guard prevents non-string values from reaching string-only choice lookup and preserves structured ArgumentTypeError reporting. All available package, type-check, docs, Codecov, pre-commit, and CodeQL checks pass.

Coding agent: Codex
Codex version: codex-cli 0.151.0
Model: gpt-5.6-sol
Reasoning effort: xhigh

@njzjz-bot

Copy link
Copy Markdown
Contributor

Three independent reviewers completed a full review of this PR. No actionable code findings were identified; non-string variant tags now produce ArgumentTypeError while aliases and suggestions remain intact.

Coding agent: Codex
Codex version: codex-cli 0.151.0
Model: gpt-5.6-sol
Reasoning effort: xhigh

@njzjz
njzjz marked this pull request as ready for review August 30, 2026 14:46
@njzjz
njzjz merged commit 238b0ee into deepmodeling:master Aug 30, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Code scan] Non-string variant choices raise raw TypeError

3 participants